'''
辅助用户管理
'''
import unittest
from Lib.base.page_object.user_manager.assist_user import AssistUser
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestUserManagerAssistTest.userManager = AssistUser(login)
    TestUserManagerAssistTest.assert_class = AssertClass(login)


@allure.feature('辅助人员管理页面测试')
class TestUserManagerAssistTest:

    @allure.title('新增辅助部门')
    def test_1_create_department(self):
        '''
        新增部门
        :return:
        '''
        self.userManager.user_manager_create_department()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="新建部门成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='新建部门成功', context='新建部门')

    @allure.title('查询和编辑部门辅助部门')
    def test_2_search_and_update_department(self):
        '''
        查询和编辑部门
        :return:
        '''
        self.userManager.user_manager_search_department_update()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="编辑部门成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='编辑部门成功', context='编辑部门')

    @allure.title('查询和修改辅助部门排序')
    def test_3_search_and_sort_department(self):
        '''
        查询和修改部门排序
        :return:
        '''
        self.userManager.user_manager_search_department_sort()
        # 设置断言
        assert_arg = (By.XPATH, '//p[text()="排序成功"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='排序成功', context='编辑部门')

    @allure.title('新增辅助人员')
    def test_4_create_user(self):
        '''
        创建用户
        :return:
        '''
        self.userManager.user_manager_create_user()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "新建成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='新建成功', context='新增用户')

    @allure.title('查询辅助人员列表')
    def test_5_list_user_search(self):
        '''
        查询用户列表
        :return:
        '''
        self.userManager.user_manager_user_list_search()
        # 设置断言
        assert_arg = (By.XPATH, '//span[text()="查看人员"]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='查看人员', context='查看人员')

    @allure.title('编辑辅助人员')
    def test_6_search_user_update(self):
        '''
        编辑用户
        :return:
        '''
        self.userManager.user_manager_user_search_update()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "编辑成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='编辑成功', context='编辑用户')

    @allure.title('辅助人员密码重置， 排序 删除')
    def test_7_search_user_sort_setpassword(self):
        '''
        用户密码重置， 排序 删除等
        :return:
        '''
        self.userManager.user_manager_user_search_sort_setpassword()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "删除用户成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='删除用户成功', context='编辑用户')

    @allure.title('删除辅助部门')
    def test_8_delete_department(self):
        '''
        删除部门
        :return:
        '''
        self.userManager.user_manager_delete_department()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "删除部门成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='删除部门成功', context='编辑用户')


if __name__ == '__main__':
    pytest.main(
        ['-v', '--reruns=3',
         '--reruns-delay=2',
         './user_manager_assist_user_test.py::TestUserManagerAssistTest'])
    # pytest.main(['-v', './user_manager_assist_user_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
